<template>
	<div style="height: 600px;overflow:hidden scroll;">
     <!--  VanTree中 提供了一个 getCheckedAndIndeterminateNodes 方法，用来获取勾选的所有节点   -->
     <VanTree ref="tree" :treeNodes="treeNodes" show-checkbox />
	</div>
</template>

<script>
import VanTree from "./VanTree.vue";
export default {
  props: {
     roleId: {
       type: Number,
       required: true
     }
  },
	data () {
		return {
			treeNodes: []
		}
	},
  created() {
     this.queryTreeNodes()
  },
	methods: {
    queryTreeNodes(){
       this.$api.queryTreeNodes(this.roleId).then(({data:ret})=> {
          if (ret.status === "10000") {
             this.treeNodes = ret.data ;
          }
       })
    },
		// 勾选获取取消所有
		selectOrCancelAllNodes(flag) {
			this.treeNodes.forEach(node => {
				this.selectOrCancelNode(node, flag);
			})
		}, 
		selectOrCancelNode(node, flag) {
			node.checked = flag ; 
			if (node.children != null) {
				node.children.forEach(n => this.selectOrCancelNode(n, flag))
			}
		}
	},
  components: {
    VanTree ,
  }
}
</script>

<style>
</style>